package com.agileboot.attendance.domain.overtime.model;

import com.agileboot.attendance.domain.overtime.db.entity.AttOvertimeEntity;
import com.agileboot.attendance.domain.overtime.db.service.IOvertimeService;
import com.agileboot.common.exception.ApiException;
import com.agileboot.common.exception.error.ErrorCode;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 加班申请模型工厂类
 */
@Component
public class OvertimeModelFactory {

    @Resource
    private IOvertimeService overtimeService;

    public OvertimeModel loadById(Long id) {
        AttOvertimeEntity entity = overtimeService.getById(id);
        if (entity == null) {
            throw new ApiException(ErrorCode.Business.COMMON_OBJECT_NOT_FOUND, "加班申请");
        }
        return new OvertimeModel(entity, overtimeService);
    }

    public OvertimeModel create() {
        OvertimeModel model = new OvertimeModel();
        model.setOvertimeService(overtimeService);
        return model;
    }
} 